<?php

namespace App\Api\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;


class uploadController extends Controller
{

    public function store(Request $request){
        if ($request->isMethod('POST')) { //判断文件是否是 POST的方式上传
            $tmp = $request->file('file');
            $path = '/uploads/images'; //public下的article
            if ($tmp->isValid()) { //判断文件上传是否有效
                $FileType = $tmp->getClientOriginalExtension(); //获取文件后缀

                $FilePath = $tmp->getRealPath(); //获取文件临时存放位置

                $FileName = date('Y-m-d') . uniqid() . '.' . $FileType; //定义文件名
                Storage::disk('api')->put($FileName, file_get_contents($FilePath)); //存储文件

                return $this->success(config('conf.server_name').$path . '/' . $FileName);
            }
        }
    }

}
